import { View } from "../../../../mvc/core/View";
import { GameConst } from "../../../../component/gconst/GameConst";
import { TilePanel } from "../../equipment/TilePanel";
import { PetCpnArrangeCellRenderer } from "./PetCpnArrangeCellRenderer";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { SecTimerView } from "../../common/SecTimerView";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { TimeButton } from "../../common/button/TimeButton";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { EPetArenaSearch } from "../../../../../Message/Game/EPetArenaSearch";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
type int = number;
//class PetCpnRandomListPanel
    
    export  class PetCpnRandomListPanel extends View
    {
        constructor()
        {
            super();
            this._randomCost = GameConst.PetArenaRandomChallengeMoneyCost;
            this._oneKeyRandomCost = GameConst.PetOneKeyRandomChallengeMoneyCost;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            this._randomList = new TilePanel();
            this._randomList.setSize(530, 350);
            this._randomList.columnWidth = 530;
            this._randomList.rowHeight = 35;
            this._randomList.setStyle("cellRenderer", PetCpnArrangeCellRenderer);
            this._randomList.move(0, 0);
            this.addChild(this._randomList);
            loc1 = new GTextFormat(FontUtil.songtiName, 16, 16711680, true);
            ObjCreate.createTextField(Language.getString(54709), 115, 215, 170, 25, this, loc1);
            this._refreshTimeTxt = new SecTimerView();
            this._refreshTimeTxt.setParse("HH: mm: ss");
            this._refreshTimeTxt.mouseEnabled = false;
            this._refreshTimeTxt.x = 293;
            this._refreshTimeTxt.y = 215;
            this._refreshTimeTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._refreshTimeTxt.defaultTextFormat = loc1;
            this._refreshTimeTxt.filters = [FilterConst.glowFilter];
            this.addChild(this._refreshTimeTxt);
            this._refreshRandomBtn = new TimeButton(2);
            this._refreshRandomBtn.styleName = "ArenaRedBtn";
            this._refreshRandomBtn.label = Language.getString(54710);
            this._refreshRandomBtn.setSize(70, 24);
            this._refreshRandomBtn.move(120, 250);
            this._refreshRandomBtn.toolTipData = Language.getStringByParam(54722, this._randomCost);
            this.addChild(this._refreshRandomBtn);
            this._refreshRandomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshRandomBtnClickHandler);
            this._oneKeyRefreshRandomBtn = new TimeButton(2);
            this._oneKeyRefreshRandomBtn.styleName = "ArenaRedBtn";
            this._oneKeyRefreshRandomBtn.label = Language.getString(54948);
            this._oneKeyRefreshRandomBtn.setSize(70, 24);
            this._oneKeyRefreshRandomBtn.move(300, 250);
            this._oneKeyRefreshRandomBtn.toolTipData = Language.getStringByParam(54735, this._oneKeyRandomCost);
            this.addChild(this._oneKeyRefreshRandomBtn);
            this._oneKeyRefreshRandomBtn.addEventListener(flash.events.MouseEvent.CLICK, this.RandomBtnClickHandler);
            ObjCreate.createTextField(Language.getString(54711), 110, 280, 170, 20, this);
            this._costTxt = ObjCreate.createTextField(this._randomCost.toString(), 170, 280, 170, 20, this);
            ObjCreate.createBitmap(ImagesConst.Tongqian_bind, 202, 277, this);
            ObjCreate.createTextField(Language.getString(54711), 290, 280, 170, 20, this);
            this._costTxt2 = ObjCreate.createTextField(this._oneKeyRandomCost.toString(), 350, 280, 170, 20, this);
            ObjCreate.createBitmap(ImagesConst.Tongqian_bind, 385, 277, this);
            this._tipTxt = ObjCreate.createTextField("", 0, 300, 533, 20, this, GlobalStyle.textFormat2);
            this._tipTxt.htmlText = Language.getString(54728);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            return;
        }

        protected RandomBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var event: Object /* flash.events.MouseEvent */;
            var isNeedAlert: Boolean;
            var htmlContent: string;
            var onClickHandler: Function;

            var loc1;
            htmlContent = null;
            event = arg1;
            this._refreshRandomBtn.clickHandler(null);
            isNeedAlert = !PulseSharedObject.isTodayNotTips("PetCpnOneKeyRandom");
            if (isNeedAlert) 
            {
                onClickHandler = (arg1: int, arg2: Boolean): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        refreshList(true, true);
                        Alert.resetToDefault();
                    }
                    if (arg2) 
                    {
                        PulseSharedObject.save("PetCpnOneKeyRandom", true);
                    }
                    return;
                }
                Alert.alertWinRenderer = CheckBoxWin;
                htmlContent = Language.getStringByParam(54735, this._oneKeyRandomCost);
                Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            else 
            {
                this.refreshList(true, true);
            }
            return;
        }

        public updateList(arg1: Array<any>): void
        {
            this._randomList.dataProvider = new DataProvider(arg1);
            return;
        }

        public updateRefreshTime(arg1: int): void
        {
            this._refreshTimeTxt.setLeftTime(arg1);
            return;
        }

        public refreshList(arg1: Boolean, arg2: Boolean=false): void
        {
            var loc1=0;
            if (arg2) 
            {
                loc1 = EPetArenaSearch._EPetArenaSearchFunctionalRandom;
            }
            else 
            {
                loc1 = EPetArenaSearch._EPetArenaSearchChallengeRandom;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnSearch, {"searchType": loc1, "perPage": 5, "targetPage": 1, "isCostMoney": arg1}));
            return;
        }

        /* internal  */onRefreshRandomBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var isNeedAlert: Boolean;
            var htmlContent: string;
            var onClickHandler: Function;

            var loc1;
            htmlContent = null;
            e = arg1;
            this._oneKeyRefreshRandomBtn.clickHandler(null);
            isNeedAlert = !PulseSharedObject.isTodayNotTips("PetCpnRandom");
            if (isNeedAlert) 
            {
                onClickHandler = (arg1: int, arg2: Boolean): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        refreshList(true);
                        Alert.resetToDefault();
                    }
                    if (arg2) 
                    {
                        PulseSharedObject.save("PetCpnRandom", true);
                    }
                    return;
                }
                Alert.alertWinRenderer = CheckBoxWin;
                htmlContent = Language.getStringByParam(54721, this._randomCost);
                Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            else 
            {
                this.refreshList(true);
            }
            return;
        }

        /* internal */ /* var */_randomList: TilePanel;

        /* internal */ /* var */_refreshTimeTxt: SecTimerView;

        /* internal */ /* var */_refreshRandomBtn: TimeButton;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneKeyRefreshRandomBtn: TimeButton;

        /* internal */ /* var */_randomCost: int;

        /* internal */ /* var */_oneKeyRandomCost: int;
    }
